cmake_minimum_required(VERSION 3.5)  
  
# 设置项目名称和版本（这里假设没有版本号）  
project(MyQtApp)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
  
# 设置C++11标准  
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)  
  

# 尝试查找 Qt5
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED QUIET)
if(Qt5_FOUND)
    message(STATUS "Found Qt5: ${Qt5_VERSION}")
    set(QT_VERSION 5)
    set(QT_COMPONENTS Core)
else()
# 尝试查找 Qt6
find_package(Qt6 COMPONENTS Core Gui Widgets REQUIRED QUIET)
if(Qt6_FOUND)
    message(STATUS "Found Qt6: ${Qt6_VERSION}")
    set(QT_VERSION 6)
    set(QT_COMPONENTS Core)
endif()
endif()


# 如果既未找到 Qt5，也未找到 Qt6，报错
if(NOT QT_VERSION)
    message(FATAL_ERROR "Qt5 or Qt6 is required!")
endif()
  
add_definitions(-DQT_DEPRECATED_WARNINGS)  
  
  
# 添加源文件  
set(SOURCES  
    Controls/codeeditor.cpp  
    HighLight.cpp  
    main.cpp  
    mainwindow.cpp  
)  
  
# 添加头文件  
set(HEADERS  
    Controls/codeeditor.h  
    HighLight.h  
    mainwindow.h  
)  
  

# 创建可执行文件  
add_executable(MyQtApp ${SOURCES} ${HEADERS}) # 注意：通常HEADERS不直接添加到可执行文件中  

  
# 链接Qt库  
target_link_libraries(MyQtApp PUBLIC Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets)  
  

